using System;
using NUnit.Framework;
using AleaClasses;
using System.Xml;

namespace TestAleaClasses
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	[TestFixture]
	public class Class1
	{
		// just testing to see if we can construct a basic graph and not error.
		[Test]
		public void ConstructAleaGraph()
		{
			TAleaGraph lAleaGraph = new TAleaGraph();

			TLabel lLabel;
			
			lLabel = new TLabel("First Label", "This is the first label");
			lAleaGraph.Labels.Add(lLabel);
			lLabel = new TLabel("Second Label", "This is the second label");
			lAleaGraph.Labels.Add(lLabel);
			lLabel = new TLabel("Third Label", "And, this is the third label");
			lAleaGraph.Labels.Add(lLabel);

			TNode lNode;
			TNode lNode2;
			TEdge lEdge;

			lNode = new TNode("Start", "Start Node", "This is the Start Node", "thefilename");
			lNode2 = new TNode("Node A", "This is Node A", "thefilename");
			lAleaGraph.Nodes.Add(lNode);
			lAleaGraph.Nodes.Add(lNode2);
			lEdge = new TEdge(lNode, lNode2, null, false);
			lNode.Edges.Add(lEdge);

			lNode = new TNode("Node B", "This is Node B", "thefilename");
			lAleaGraph.Nodes.Add(lNode);
			lEdge = new TEdge(lNode2, lNode, null, false);
			lNode2.Edges.Add(lEdge);
			lEdge = new TEdge(lNode, lNode2, null, false);
			lNode.Edges.Add(lEdge);
			lEdge = new TEdge(lNode, null, lLabel, false);
			lNode.Edges.Add(lEdge);

			// Now write it to file.
			XmlDocument ldoc = new XmlDocument();
			XmlElement rootelem = lAleaGraph.SaveToXml(ldoc);
			ldoc.AppendChild(rootelem);

			ldoc.Save(".\\Test_ConstructAleaGraph.AleaGraph.xml");
		}

		[Test]
		public void ReloadAleaGraph()
		{
			XmlDocument ldoc = new XmlDocument();
			ldoc.Load(".\\Test_ConstructAleaGraph.AleaGraph.xml");
			XmlElement lElem = ldoc.ChildNodes[0] as XmlElement;

			TAleaGraph lAleaGraph = new TAleaGraph(lElem);

			// Now write it to file again.
			ldoc = new XmlDocument();
			XmlElement rootelem = lAleaGraph.SaveToXml(ldoc);
			ldoc.AppendChild(rootelem);

			ldoc.Save(".\\Test_ConstructAleaGraph2.AleaGraph.xml");
		}
	}
}
